package com.library;

import java.io.FileOutputStream;
import java.util.List;

import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;

import com.library.portlet.util.Constants;

public class testExcelGeneration {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		
		HSSFWorkbook myWorkbook = new HSSFWorkbook();
	    HSSFSheet mySheet = myWorkbook.createSheet();
	    
	    int rowNum =4;
		 HSSFRow myRow = null;
		    HSSFCell myCell = null;
		    String excelData[][] = new String[1][6];
		    excelData[0][0] = "country";
		    excelData[0][1] = "gold";
		    excelData[0][2] = "silver";
		    excelData[0][3] = "bronze";
		    excelData[0][4] = "total";

		    myRow = mySheet.createRow(rowNum);

		    for (int cellNum = 0; cellNum < 6; cellNum++) {
		        myCell = myRow.createCell(cellNum);
		        myCell.setCellValue(excelData[0][cellNum]);

		    }

		    try {
		        FileOutputStream out = new FileOutputStream("G:\\testexcel.xls");
		        myWorkbook.write(out);
		        out.close();
		    } catch (Exception e) {
		        e.printStackTrace();
		    }
		
		/************************************************************************************************/
		
		/*
		String xlsSheetLocation = Constants.xlsSheetLocation ;
		HSSFWorkbook myWorkbook = new HSSFWorkbook();
	    HSSFSheet mySheet = myWorkbook.createSheet();
	    
	    HSSFRow myRow = null;
	    HSSFCell myCell = null;
	    String excelData[][] = new String[1][4]; 
		excelData[0][0] = Constants.bookId;
		excelData[0][1] = Constants.bookTitle;
		excelData[0][2] = Constants.bookAuthor;
		excelData[0][3] = Constants.dateAdded;*/
		
		  
		/*int noOfRows = 0;
		try {
			List<LMSBook> lmsBookList = LMSBookLocalServiceUtil.getLMSBooks(0, -1);
			noOfRows = lmsBookList.size();
		} catch (SystemException e1) {
			e1.printStackTrace();
		}
		myRow = mySheet.createRow(noOfRows);*/
		
/*		for(int i=0;i<4;i++){
			myCell = myRow.createCell(i);
			myCell.setCellValue("hiii");

		}
		

		//write the file object and Close..
		try{
			System.out.println("inside try block of conn-closing");
			
			FileOutputStream out = new FileOutputStream(xlsSheetLocation);
			myWorkbook.write(out);
			out.close();
		}catch(Exception e){
			e.printStackTrace();
		}
		*/
		
	}

}
